#include "hf_WeatherData.h"

HeadFirstS::HF_WeatherData::HF_WeatherData()
{

}

void HeadFirstS::HF_WeatherData::registerObserver(HeadFirstS::HF_Observer *o)
{
    m_pObservers.emplace_back(o);
}

void HeadFirstS::HF_WeatherData::removeObserver(HeadFirstS::HF_Observer *o)
{
    m_pObservers.remove(o);
}

void HeadFirstS::HF_WeatherData::notifyObservers()
{
    std::cout << "notify observers: " << std::endl;
    std::list<HF_Observer*>::iterator it = m_pObservers.begin();
    for(it; it != m_pObservers.end(); ++it) {
        (*it)->update(m_temperature,
                        m_humidity,
                        m_pressure);
    }


//    for (auto observer = m_pObservers.begin(); observer != m_pObservers.end(); observer++) {
//                (*observer)->update(m_temperature, m_humidity, m_pressure);
//            }
}

void HeadFirstS::HF_WeatherData::MeasurementsChanged()
{
    notifyObservers();
}

void HeadFirstS::HF_WeatherData::setMeasurements(float temperature, float humidity, float pressure)
{
    this->m_temperature = temperature;
    this->m_humidity    = humidity   ;
    this->m_pressure    = pressure   ;

    MeasurementsChanged();
}
